package com.fmy.jurisdiction.modular.controller;


import com.fmy.jurisdiction.core.commons.kits.SecurityKit;
import com.fmy.jurisdiction.core.web.call.ResponseCall;
import com.fmy.jurisdiction.core.web.specs.Response;
import com.fmy.jurisdiction.core.web.util.WebUtil;
import com.fmy.jurisdiction.modular.model.AdminDept;
import com.fmy.jurisdiction.modular.service.IAdminDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * <p>
 * 部门表 前端控制器
 * </p>
 *
 * @author Mr.fmy
 * @since 2019-09-17
 */
@RestController
@RequestMapping("/admin-dept")
public class AdminDeptController {

    @Autowired
    private IAdminDeptService deptService;

//    /**
//     * 所有 树列表
//     */
//    @GetMapping("/list")
//    public Response list() {
//        return ResponseCall.success(deptService.getChildren(null));
//    }

    /**
     * 个人 树列表
     */
    @GetMapping("/list-personal")
    public Response listPersonal() {
        return ResponseCall.success(deptService.getChildren(SecurityKit.getDeptId()));
    }

    @PostMapping("/add")
    @Valid
    public Response add(AdminDept dept, BindingResult result) {
        WebUtil.validationParam(result);
        return WebUtil.vailBusiness(deptService.add(dept), "增添部门失败、请稍后重试");
    }

    @PostMapping("/modify")
    public Response modify(Integer id, String name, Integer sort) {
        return WebUtil.vailBusiness(deptService.modify(id, name, sort), "修改部门失败、请重试");
    }

    @PostMapping("/del")
    public Response del(Integer id) {
        return WebUtil.vailBusiness(deptService.del(id), "删除部门失败、请重试");
    }
}

